package com.yunhe.authority.repository.company;

import com.yunhe.authority.domain.company.CompanySupportingInfo;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @ClassName: CompanySupportingInfoRepository
 * @Description:
 * @author: GongDaCheng
 * @Date: 11:02 2021/7/14
 */
@Repository
public interface CompanySupportingInfoRepository extends Neo4jRepository<CompanySupportingInfo, Long> {


    /**
     * @Description 企业配套信息绑定企业
     * @Param Long companyId, Long id
     * @Return
     * @Date 2021/7/14 11:10
     */
    @Query("match (c:Company), (csInfo:CompanySupportingInfo) where ID(c)  ={companyId}  and ID(csInfo) ={id}  create (c)-[r:HAS_SUPPORTING_INFO]->(csInfo)")
    void bindCompany(@Param("companyId") Long companyId, @Param("id") Long id);

    /**
     * @Description 根据企业id查询企业配套信息
     * @Param Long companyId
     * @Return CompanySupportingInfo
     * @Date 2021/7/14 14:13
     */
    @Query("match (c:Company)-[r:HAS_SUPPORTING_INFO]->(csInfo:CompanySupportingInfo) where ID(c) ={companyId} return csInfo")
    CompanySupportingInfo getByCompanyId(@Param("companyId") Long companyId);

    /**
     * @Description 根据企业id解绑并删除企业配套信息
     * @Param Long companyId
     * @Return
     * @Date 2021/8/17 17:49
     */
    @Query("match (c:Company)-[r:HAS_SUPPORTING_INFO]->(csInfo:CompanySupportingInfo) where ID(c) ={companyId} delete r, csInfo")
    void unbindAndDelete(@Param("companyId") Long companyId);
}
